# Contributor: psykose <alice@ayaya.dev>
# Maintainer: psykose <alice@ayaya.dev>
pkgname=pcsx2
pkgver=1.7.2913
pkgrel=0
_cubeb=773f16b7ea308392c05be3e290163d1f636e6024
_glslang=c9706bdda0ac22b9856f1aa8261e5b9e15cd20c5
_imgui=60bea052a92cbb4a93b221002fdf04f0da3698e1
_libchdr=5de1a59019815ccdbba0fe07c71b31406d023248
pkgdesc="Playstation 2 emulator"
url="https://github.com/PCSX2/pcsx2"
arch="x86_64" # only x86_64 supported for now
license="GPL-3.0-or-later AND LGPL-3.0-or-later"
makedepends="
	alsa-lib-dev
	cmake
	doxygen
	eudev-dev
	fmt-dev
	graphviz
	libaio-dev
	libpcap-dev
	libsamplerate-dev
	libzip-dev
	libzip-tools
	pulseaudio-dev
	rapidyaml-dev
	samurai
	sdl2-dev
	soundtouch-dev
	vulkan-headers
	wayland-dev
	wxgtk3-dev
	zstd-dev
	zstd-static
	"
subpackages="$pkgname-doc"
source="https://github.com/PCSX2/pcsx2/archive/refs/tags/v$pkgver/pcsx2-v$pkgver.tar.gz
	cubeb-$_cubeb.tar.gz::https://github.com/mozilla/cubeb/archive/$_cubeb.tar.gz
	glslang-$_glslang.tar.gz::https://github.com/KhronosGroup/glslang/archive/$_glslang.tar.gz
	imgui-$_imgui.tar.gz::https://github.com/ocornut/imgui/archive/$_imgui.tar.gz
	libchdr-$_libchdr.tar.gz::https://github.com/rtissera/libchdr/archive/$_libchdr.tar.gz
	fix-iovec-define.patch
	version.patch
	unbundle-vulkan.patch
	"
options="!check" # no point in running emulator tests

prepare() {
	default_prepare

	rmdir "$builddir"/3rdparty/cubeb/cubeb
	rmdir "$builddir"/3rdparty/glslang/glslang
	rmdir "$builddir"/3rdparty/imgui/imgui
	rmdir "$builddir"/3rdparty/libchdr/libchdr

	ln -sfv "$srcdir"/cubeb-$_cubeb \
		"$builddir"/3rdparty/cubeb/cubeb
	ln -sfv "$srcdir"/glslang-$_glslang \
		"$builddir"/3rdparty/glslang/glslang
	ln -sfv "$srcdir"/imgui-$_imgui \
		"$builddir"/3rdparty/imgui/imgui
	ln -sfv "$srcdir"/libchdr-$_libchdr \
		"$builddir"/3rdparty/libchdr/libchdr

	sed -i \
		-e "s|@@VERSION@@|$pkgver|g" \
		-e "s|@@PKGREL@@|$pkgrel|g" \
		cmake/Pcsx2Utils.cmake
}

build() {
	# TODO: wayland is broken with wxgtk 3.0, revisit in 3.1
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=Release \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DDISABLE_ADVANCE_SIMD=ON \
		-DDISABLE_BUILD_DATE=ON \
		-DDISABLE_PCSX2_WRAPPER=ON \
		-DENABLE_TESTS="$(want_check && echo ON || echo OFF)" \
		-DCUBEB_API=ON \
		-DDISABLE_SETCAP=ON \
		-DLTO_PCSX2_CORE=ON \
		-DNO_TRANSLATION=ON \
		-DPACKAGE_MODE=ON \
		-DSDL2_API=ON \
		-DUSE_NATIVE_TOOLS=ON \
		-DUSE_SYSTEM_FMT=ON \
		-DUSE_SYSTEM_RYML=ON \
		-DUSE_SYSTEM_ZSTD=ON \
		-DUSE_VTUNE=OFF \
		-DUSE_VULKAN=ON \
		-DWAYLAND_API=OFF \
		-DX11_API=ON \
		-DXDG_STD=ON
	cmake --build build
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

sha512sums="
5dd7c6595aa90674f0cc42cc4449b463df6566246647c2dd1682456195b55eff7e6d5ecb10f5a5530154bebca1d3bbe9ad17622e6d73923d6deffcf8262bd4fe  pcsx2-v1.7.2913.tar.gz
33abe2bc426b06c3c6cb557fe1be62725f1dc56776d02ec6651ef8710d3a5d302b1f730ceaefe516ff1974775cdabd3753f24436c705af3c6e98fd5dabb6b015  cubeb-773f16b7ea308392c05be3e290163d1f636e6024.tar.gz
5ff0902e95592525b2671788bf27717c85d0876b31e96374eff5128f9bf7caf93bb636e4d5e1916a5d641715a780172308403bd49305d9a07cf66358d7e6407c  glslang-c9706bdda0ac22b9856f1aa8261e5b9e15cd20c5.tar.gz
690637e619eafb9c15036f45574f8afc25c70a3210fdbb2704d49244a9360fc401807b3cdff6085a4d3a0956f7ff64dcdb8e5142375910a03e74eaa437672bc0  imgui-60bea052a92cbb4a93b221002fdf04f0da3698e1.tar.gz
4fee3a448c9044aca83fffae4a9c821e37e65ee6b43022c3354b1d782c8a5e6ac675a54fe2248897969aa3fd05dfaccbc8f67f8d6547458c012326b7d5a5c990  libchdr-5de1a59019815ccdbba0fe07c71b31406d023248.tar.gz
c70a510b197e30fb6a5506c71e0075bbeb79d4b76ba6f5ef285c6f984b6c262cbe4bf5338714a411f5b70fde3b0be6e8ae73642343d18b267d0f67ea0d7503c7  fix-iovec-define.patch
e6a11952afe010b20074c847ab3c48fafcfe5b0055ecf0b1d2ecd42e620d0913311c03f1019c60acd7bf68b1370e461b5c7c70fdac2c45994e8ca1ac03d63b65  version.patch
fbcdcb736b13f988ee9fff9dd11f253e2500984542bc3c913a7dd9b2abcedb206abce1be048547bf1dfc78e37e7145d5001252ec893ced948537ab8e9d0b5c24  unbundle-vulkan.patch
"
